package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.Date;

public class Welcome extends JPanel{
	
	private JLabel lbl_Welcome;
	private JButton btn_Login;
	private JTextField textField_ID;
	private JLabel lbl_ID;
	private JLabel lbl_PIN;
	private JPasswordField passwordField_PIN;
	private JButton btn_Exit;
	
	private int userID;
	private int userPIN;
	private JLabel lbl_Time;
	private JLabel lbl_TimeOfLogin;
	
	public Welcome() {
		
		setPreferredSize(new Dimension(550, 400));
		setLayout(null);
		
		lbl_Welcome = new JLabel("Welcome to the ATM of Gruppe 7!");
		lbl_Welcome.setFont(new Font("SansSerif", Font.BOLD | Font.ITALIC, 24));
		lbl_Welcome.setBounds(99, 21, 382, 32);
		add(lbl_Welcome);
		
		btn_Login = new JButton("Login!");
		btn_Login.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Login.setBounds(377, 256, 104, 40);
		add(btn_Login);
		
		textField_ID = new JTextField();
		textField_ID.setFont(new Font("SansSerif", Font.PLAIN, 16));
		textField_ID.setBounds(201, 131, 180, 30);
		add(textField_ID);
		textField_ID.setColumns(10);
		
		lbl_ID = new JLabel("ID");
		lbl_ID.setFont(new Font("SansSerif", Font.BOLD, 16));
		lbl_ID.setBounds(126, 138, 46, 14);
		add(lbl_ID);
		
		lbl_PIN = new JLabel("PIN");
		lbl_PIN.setFont(new Font("SansSerif", Font.BOLD, 16));
		lbl_PIN.setBounds(126, 181, 46, 14);
		add(lbl_PIN);
		
		passwordField_PIN = new JPasswordField();
		passwordField_PIN.setFont(new Font("SansSerif", Font.PLAIN, 16));
		passwordField_PIN.setBounds(201, 174, 180, 30);
		add(passwordField_PIN);
		
		btn_Exit = new JButton("Exit");
		btn_Exit.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Exit.setBounds(99, 261, 100, 40);
		add(btn_Exit);
		
		Date dateAndTime = Calendar.getInstance().getTime();
		lbl_Time = new JLabel(dateAndTime.toString());
		lbl_Time.setFont(new Font("SansSerif", Font.BOLD, 14));
		lbl_Time.setBounds(175, 89, 233, 19);
		add(lbl_Time);
		
		lbl_TimeOfLogin = new JLabel("Time of Login");
		lbl_TimeOfLogin.setFont(new Font("SansSerif", Font.BOLD, 14));
		lbl_TimeOfLogin.setBounds(240, 64, 104, 21);
		add(lbl_TimeOfLogin);
	}
	
	public void addActionListener(ActionListener event) {
		btn_Login.addActionListener(event);
		btn_Exit.addActionListener(event);
	}

	public void clearFields(){
		textField_ID.setText("");
		passwordField_PIN.setText("");
		userID = 0;
		userPIN = 0;
	}
	
	public JButton getExit(){
		return btn_Exit;
	}
	
	public int getLoginUserID(){
		try {
			userID = Integer.parseInt(textField_ID.getText().trim()); 	
		} catch (Exception exc) {
		}
		return userID;
	}
	
	public int getLoginPin(){
		try {
			char[] pin = passwordField_PIN.getPassword();
			userPIN = Integer.parseInt(new String(pin));
		} catch (Exception exc) {
		}
		return userPIN;
	}
}//end class

